import { useSelector } from 'react-redux'
import { IRoorState } from '../store'
import { ChatListType } from '../store/messageSlice'

export function useMessageList() {
  // 获取消息列表
  const messageList = useSelector((state: IRoorState) => state.message.messageList)
  // 当前选中的对话key
  const selectedKey = useSelector((state: IRoorState) => state.message.selectedKey)
  // 是否正在加载
  const loading = useSelector((state: IRoorState) => state.message.loading)
  // 获取当前的对话
  const currentChatList = messageList.find(
    (item: ChatListType) => item.key === selectedKey
  )?.chatList
  // 获取当前选中的模型
  const selectedModel = useSelector((state: IRoorState) => state.message.selectedModel)

  return {
    messageList,
    selectedKey,
    loading,
    selectedModel,
    currentChatList
  }
}
